/*
 * This source code is part of TWaver 4.0
 *
 * Serva Software PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 * Copyright 2002 - 2011 Serva Software. All rights reserved.
 */

package demo;

import javax.swing.SwingUtilities;

import twaver.Element;
import twaver.ShapeLink;
import twaver.TUIManager;
import twaver.TWaverConst;
import twaver.TWaverUtil;
import twaver.network.NetworkToolBarFactory;
import twaver.table.Category;
import demo.chart.ChartPopupMenuGenerator;
import demo.editor.chassis.GridButton;
import demo.editor.chassis.EquipmentButton.CardButton;
import demo.editor.chassis.EquipmentButton.PortButton;
import demo.editor.chassis.EquipmentButton.RackButton;
import demo.editor.chassis.EquipmentButton.ShelfButton;
import demo.editor.chassis.EquipmentButton.SlotButton;
import demo.editor.drawing.DrawingButton.CubicCurveButton;
import demo.editor.drawing.DrawingButton.LineButton;
import demo.editor.drawing.DrawingButton.PolygonButton;
import demo.editor.drawing.DrawingButton.PolylineButton;
import demo.editor.drawing.DrawingButton.QuadCurveButton;
import demo.editor.drawing.DrawingButton.RectangleButton;
import demo.editor.drawing.DrawingButton.RoundButton;
import demo.editor.drawing.DrawingButton.StarButton;
import demo.editor.drawing.DrawingButton.TextButton;
import demo.editor.drawing.DrawingButton.TriangleButton;
import demo.editor.drawing.element.CubicCurve;
import demo.editor.drawing.element.Line;
import demo.editor.drawing.element.Polygon;
import demo.editor.drawing.element.Polyline;
import demo.editor.drawing.element.QuadCurve;
import demo.editor.drawing.element.Rectangle;
import demo.editor.drawing.element.Round;
import demo.editor.drawing.element.Star;
import demo.editor.drawing.element.Triangle;
import demo.network.miscellaneous.instrument.element.Clock;
import demo.network.miscellaneous.instrument.element.CustomUINode;
import demo.network.miscellaneous.instrument.element.Thermometer;
import demo.resource.DemoResourceAgent;
import demo.table.person.Person;

public class Demo {
	 
	public static void init(){
    	TWaverUtil.init(TWaverConst.EN_US, DemoResourceAgent.class);
    	registerDefaults();
    	registerIcon();
    	registerImage();
    	registerCategory();
    	registerBeanInfo();
    	registerAttachment();
    	registerToolbarButton();
        
        TUIManager.setLinkBundleFilter(new twaver.VisibleFilter(){
        	   public boolean isVisible(Element element) {
        	    return !(element instanceof ShapeLink);
        	   }
        });
	}
	
	private static void registerDefaults(){
		TUIManager.registerDefault(TWaverConst.NETWORK_FULL_SCREEN_KEYBOARD, "F11"); 
		TUIManager.registerDefault(TWaverConst.PROPERTYNAME_LINK_BUNDLE_EXPAND, Boolean.TRUE);
		TUIManager.registerDefault(TWaverConst.TABLE_SHOW_PREDEFINED_COLUMNS_IN_POPUPMENU, Boolean.FALSE);
		TUIManager.registerDefault(TWaverConst.TCHART_PIE_3D, Boolean.TRUE); 
		
		TUIManager.registerDefault(TWaverConst.NETWORK_ANIMATE_COMPONENT_ATTACHMENT, Boolean.TRUE);
        TUIManager.registerDefault(TWaverConst.NETWORK_ANIMATE_SUBNETWORK_ENTER, Boolean.TRUE);
        TUIManager.registerDefault(TWaverConst.NETWORK_ANIMATE_ELEMENT_MOVE, Boolean.TRUE);
        TUIManager.registerDefault(TWaverConst.NETWORK_ANIMATE_ELEMENT_DELETE, Boolean.TRUE);
        TUIManager.registerDefault(TWaverConst.NETWORK_ANIMATE_ELEMENT_RESIZE, Boolean.TRUE);
        
		TUIManager.registerDefault(TWaverConst.TCHART_POPUP_MENU_GENERATOR, ChartPopupMenuGenerator.INSTANCE);
	}
	
	private static void registerIcon(){
		TUIManager.registerIcon(CustomUINode.class, "/demo/network/miscellaneous/instrument/switch_icon.png");
		TUIManager.registerIcon(Thermometer.class, "/demo/network/miscellaneous/instrument/thermometer_icon.png");
		TUIManager.registerIcon(Clock.class, "/demo/network/miscellaneous/instrument/clock_icon.png");			
		TUIManager.registerIcon(Rectangle.class, "/demo/editor/drawing/icons/rectangle.png");		
		TUIManager.registerIcon(Round.class, "/demo/editor/drawing/icons/round.png");					
		TUIManager.registerIcon(Triangle.class, "/demo/editor/drawing/icons/triangle.png");
		TUIManager.registerIcon(Star.class, "/demo/editor/drawing/icons/star.png");		
		TUIManager.registerIcon(Line.class, "/demo/editor/drawing/icons/line.png");
		TUIManager.registerIcon(Polygon.class, "/demo/editor/drawing/icons/polygon.png");
		TUIManager.registerIcon(Polyline.class, "/demo/editor/drawing/icons/polyline.png");
		TUIManager.registerIcon(QuadCurve.class, "/demo/editor/drawing/icons/quadcurve.png");
		TUIManager.registerIcon(CubicCurve.class, "/demo/editor/drawing/icons/cubiccurve.png");
	}
	
	private static void registerImage(){
		TUIManager.registerImage(CustomUINode.class, "/demo/network/miscellaneous/instrument/switch.png");			
		TUIManager.registerImage(Thermometer.class, "/demo/network/miscellaneous/instrument/thermometer_image.png");			
	}
	
	private static void registerAttachment(){
        for(int i=1; i<=8; i++){
        	String attachmentName = "attachment" + i;
        	String attachmentURL = "/demo/resource/images/attachment" + i + ".png";
        	TUIManager.registerAttachment(attachmentName, attachmentURL);
        }
	}
	
	private static void registerCategory(){
        Category.registerCategory("group1", "GROUP1", "All properties in this group need to be validated.");
        Category.registerCategory("group2", "GROUP2");
        Category.registerCategory("kpi", "KPI");
        Category.registerCategory("thermometer", "THERMOMETER");
        Category.registerCategory("sheet1", "SHEET1");
        Category.registerCategory("sheet2", "SHEET2");
        Category.registerCategory("sheet3", "SHEET3");
        Category.registerCategory("other", "OTHER");	       
		Category.registerCategory("chart", "Chart");
		Category.registerCategory("global", "Global");
		Category.registerCategory("legend", "Legend", false);
		Category.registerCategory("content", "Content", false);
		Category.registerCategory("scale", "Scale");
		Category.registerCategory("xAxis", "XAxis", false);
		Category.registerCategory("yAxis", "YAxis", false);
		Category.registerCategory("xScale", "XScale", false);
		Category.registerCategory("yScale", "YScale", false);
		Category.registerCategory("line", "Line", false);
		Category.registerCategory("bar", "Bar", false);        
	}
	
	private static void registerBeanInfo(){
        TWaverUtil.registerBeanInfoWithoutDefault(Person.class);
        TWaverUtil.registerBeanInfoWithoutDefault(DemoNode.class);
	}
	
	private static void registerToolbarButton(){
		NetworkToolBarFactory.registerButton("RackButton", RackButton.class);	
		NetworkToolBarFactory.registerButton("ShelfButton", ShelfButton.class);	
		NetworkToolBarFactory.registerButton("SlotButton", SlotButton.class);	
		NetworkToolBarFactory.registerButton("CardButton", CardButton.class);	
		NetworkToolBarFactory.registerButton("PortButton", PortButton.class);	
		NetworkToolBarFactory.registerButton("GridButton", GridButton.class);	
		
		NetworkToolBarFactory.registerButton("TextButton", TextButton.class);	
		NetworkToolBarFactory.registerButton("RectangleButton", RectangleButton.class);	
		NetworkToolBarFactory.registerButton("RoundButton", RoundButton.class);		
		NetworkToolBarFactory.registerButton("TriangleButton", TriangleButton.class);
		NetworkToolBarFactory.registerButton("StarButton", StarButton.class);		
		NetworkToolBarFactory.registerButton("LineButton", LineButton.class);	
		NetworkToolBarFactory.registerButton("PolygonButton", PolygonButton.class);	
		NetworkToolBarFactory.registerButton("PolylineButton", PolylineButton.class);		
		NetworkToolBarFactory.registerButton("QuadCurveButton", QuadCurveButton.class);	
		NetworkToolBarFactory.registerButton("CubicCurveButton", CubicCurveButton.class);
		
		NetworkToolBarFactory.registerButton("SquarePipeButton", demo.editor.pipe.PipeButton.SquarePipeButton.class);
		NetworkToolBarFactory.registerButton("RoundPipeButton", demo.editor.pipe.PipeButton.RoundPipeButton.class);

		NetworkToolBarFactory.registerToolbar("ChassisEditorToolbar", new String[]{
				TWaverConst.TOOLBAR_SELECTION,
				TWaverConst.TOOLBAR_UNDO,
				TWaverConst.TOOLBAR_REDO,
				TWaverConst.TOOLBAR_MAGNIFIER,
				TWaverConst.TOOLBAR_ZOOMIN,
				TWaverConst.TOOLBAR_ZOOMOUT,
				TWaverConst.TOOLBAR_ZOOMRESET,
				TWaverConst.TOOLBAR_FULLSCREEN,
				TWaverConst.TOOLBAR_OPENDATAFILE,
				TWaverConst.TOOLBAR_SAVEDATAFILE,
				TWaverConst.TOOLBAR_EXPORTIMAGE,
				TWaverConst.TOOLBAR_PRINTPREVIEW,
				TWaverConst.TOOLBAR_EXPORTSVG,
				TWaverConst.TOOLBAR_SEPARATOR_ID,	
				"RackButton",
				"ShelfButton",
				"SlotButton",
				"CardButton",
				"PortButton",
				"GridButton",
		});

		NetworkToolBarFactory.registerToolbar("PipeEditorToolbar", new String[]{
				"Selection",
				"ZoomIn",
				"ZoomOut",
				"ZoomReset",
				"FullScreen",
				"OpenDataFile",
				"SaveDataFile",
				"SquarePipeButton",	
				"RoundPipeButton"
		});
		
		NetworkToolBarFactory.registerToolbar("DrawingEditorToolbar", new String[]{
				TWaverConst.TOOLBAR_SELECTION,				
				TWaverConst.TOOLBAR_LAZYMOVE,
				TWaverConst.TOOLBAR_UNDO,
				TWaverConst.TOOLBAR_REDO,		
				TWaverConst.TOOLBAR_ZOOMIN,
				TWaverConst.TOOLBAR_ZOOMOUT,
				TWaverConst.TOOLBAR_ZOOMRESET,
				TWaverConst.TOOLBAR_OPENDATAFILE,
				TWaverConst.TOOLBAR_SAVEDATAFILE,
				TWaverConst.TOOLBAR_EXPORTIMAGE,
				TWaverConst.TOOLBAR_EXPORTSVG,
				TWaverConst.TOOLBAR_SEPARATOR_ID,	
				"TextButton",
				TWaverConst.TOOLBAR_SEPARATOR_ID,	
				"RectangleButton",
				"RoundButton",
				"TriangleButton",
				"StarButton",
				"LineButton",
				"PolylineButton",
				"PolygonButton",
				"QuadCurveButton",
				"CubicCurveButton",
		});
	}
	
    public static void main(String[] args) { 
    	SwingUtilities.invokeLater(new Runnable(){
    		public void run() {
    			Demo.init();
    	        DemoFrame demoFrame = new DemoFrame();
    	        demoFrame.setVisible(true);
    		}     
    	});     
    }
    
}